package com.wlyuan.open.scanner.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wlyuan.open.scanner.application.annotation.DataScope;
import com.wlyuan.open.scanner.dao.entity.PayDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author yuanjie
 * @since 2022-12-27
 */
public interface PayMapper extends BaseMapper<PayDO> {

    /**
     * 获取收付款列表
     *
     * @return
     */
    @Select("select t.id,t.up,t.down,t.type,t.tenant_id as tenantId,t.create_time as createTime,t.update_time as updateTime from t_pay t order by t.up asc " +
            "OFFSET ( #{pageNum} -1)* #{pageSize} ROWS FETCH next #{pageSize} rows only")
    @DataScope(column = "tenant_id", alias = "t")
    List<PayDO> list(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @Select("select count(*) from t_pay t ")
    @DataScope(column = "tenant_id", alias = "t")
    Integer count();

    @Select("select count(*) from t_pay t where t.tenant_id = #{tenantId}")
    @DataScope(column = "tenant_id", alias = "t")
    Integer countByTenantId(@Param("tenantId") Long tenantId);

    @Select("select t.id,t.up,t.down,t.type,t.tenant_id as tenantId,t.create_time as createTime,t.update_time as updateTime from t_pay t where t.tenant_id = #{tenantId} order by t.up asc  " +
            "OFFSET ( #{pageNum} -1)* #{pageSize} ROWS FETCH next #{pageSize} rows only")
    @DataScope(column = "tenant_id", alias = "t")
    List<PayDO> listByTenantId(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize, @Param("tenantId") Long tenantId);

    @Select("select count(*) from t_pay t where t.type = #{type}")
    @DataScope(column = "tenant_id", alias = "t")
    Integer countByType(@Param("type") Integer type);

    @Select("select t.id,t.up,t.down,t.type,t.tenant_id as tenantId,t.create_time as createTime,t.update_time as updateTime from t_pay t where t.type = #{type} order by t.up asc  " +
            "OFFSET ( #{pageNum} -1)* #{pageSize} ROWS FETCH next #{pageSize} rows only")
    @DataScope(column = "tenant_id", alias = "t")
    List<PayDO> listByType(@Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize, @Param("type") Integer type);
}
